﻿using System;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Point pStart;
        private void Label1_MouseDown(object sender, MouseEventArgs e)
        {
            pStart = new Point(e.X, e.Y);
        }

        private void Label1_MouseMove(object sender, MouseEventArgs e)
        {   
            // 只有按下左键才允许移动
            if (e.Button == System.Windows.Forms.MouseButtons.Left) {
                //设置窗体的坐标
              //  this.Location.X = e.X - pStart.X + this.Location.X;
               // this.Location.Y = e.Y - pStart.Y + this.Location.Y;
                this.Location = new Point(  e.X - pStart.X + this.Location.X,e.Y - pStart.Y + this.Location.Y);
            }
        }

        private void Label2_Click(object sender, EventArgs e)
        {
            this.Dispose();  //关闭窗口
        }

        private void TextBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void BtnLogin_Click(object sender, EventArgs e)
        {
            String uid = txtUid.Text.Trim();
            String pwd = txtPwd.Text;
            if (uid.Length == 0 || pwd.Length == 0) {
                MessageBox.Show("请输入完整信息");
                return ;
            }
            String connetStr = "server=localhost;port=3306;user id=root;password=root; database=mydb";
            String sql = String.Format("select count(*) from LoginTable where uid='{0}' and pwd='{1}';", uid, pwd);
            
            MySqlConnection conn = new MySqlConnection(connetStr);
            conn.Open();
            MySqlCommand cmd = new MySqlCommand(sql,conn);
            Object result = cmd.ExecuteScalar();
            int r = Convert.ToInt32(result);
            if (r>0) {
                MessageBox.Show("登录成功");
            } else{ 
                MessageBox.Show("登录失败");
            }
        }

        private void Label3_Click(object sender, EventArgs e)
        {
            // 注册新窗口，下面的  注册窗口 为 新窗口名称，在属性中定义
            注册窗口 zc = new 注册窗口();
            zc.Show();
        }
    }
}
